"""
主题: 在局部变量域中执行代码
问题: 你想在使用范围内执行某个代码片段，并且希望在执行后所有的结果都不可见。
提示 : 
"""
b = 0
a = 13
exec('b = a + 1')   # NOSONAR
print(f"{b = }")

def test1():
    a = 1
    loc = locals()
    exec('b = a + 1')
    b = loc['b']
    print(b)

def test2():
    x = 2
    loc = locals()
    print(loc)
    exec('x += 1')
    print(loc)
    locals()   # NOSONAR
    print(loc)


def test3():
    a = 3
    loc = {'a': a}
    glb = {}
    exec('b = a + 1', glb, loc)
    b = loc['b']
    print(b)

def recipe1():
    test1()

def recipe2():
    test2()

def recipe3():
    test3()

def main():
    print('recipe1'.center(20, '*'))
    recipe1()
    print('recipe2'.center(20, '*'))
    recipe2()
    print('recipe3'.center(20, '*'))
    recipe3()

if __name__ == '__main__':
    main()                